using System;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
namespace BMC.ARSystem
{
	[ClassInterface, Guid("1b800b0a-f569-48da-a6f2-481ade811cab"), ProgId("BMC.ARSystem.ApplicationContainer")]
	public class ApplicationContainer : Container
	{
		private static ExternalReference _primaryFormIndicator = new ExternalReference(32777);
		private static ExternalReference _formsIndicator = new ExternalReference(32771);
		private static ExternalReference _packListIndicator = new ExternalReference(32840);
		private static ExternalReference _supportFileIndicator = new ExternalReference(32789);
		private int _version;
		private bool _formsAsMaximized;
		private string _autoLayoutStylesheet;
		private bool _addFormActionFields;
		private bool _resultListFixedHeader;
		private bool _disableBeginTask;
		private string _defaultObjectPermissions;
		private ByteList _smallIcon;
		private ByteList _aboutBoxImage;
		private string _formActionFields;
		private string _formActionPageProperty;
		private string _primaryForm;
		private string _primaryView;
		private ArrayList _forms;
		private ArrayList _packingLists;
		private ArrayList _supportFiles;
		private ArrayList _formDataList;
		private string _state;
		private ArrayList _accessPoints;
		private ArrayList _statisticForms;
		public string State
		{
			get
			{
				return this._state;
			}
			set
			{
				this._state = value;
			}
		}
		public int Version
		{
			get
			{
				return this._version;
			}
			set
			{
				this._version = value;
			}
		}
		public bool FormsAsMaximized
		{
			get
			{
				return this._formsAsMaximized;
			}
			set
			{
				this._formsAsMaximized = value;
			}
		}
		public string AutoLayoutStylesheet
		{
			get
			{
				return this._autoLayoutStylesheet;
			}
			set
			{
				this._autoLayoutStylesheet = value;
			}
		}
		public bool AddFormActionFields
		{
			get
			{
				return this._addFormActionFields;
			}
			set
			{
				this._addFormActionFields = value;
			}
		}
		public bool ResultListFixedHeader
		{
			get
			{
				return this._resultListFixedHeader;
			}
			set
			{
				this._resultListFixedHeader = value;
			}
		}
		public bool DisableBeginTask
		{
			get
			{
				return this._disableBeginTask;
			}
			set
			{
				this._disableBeginTask = value;
			}
		}
		public string DefaultObjectPermissions
		{
			get
			{
				return this._defaultObjectPermissions;
			}
			set
			{
				this._defaultObjectPermissions = value;
			}
		}
		public ByteList SmallIconImage
		{
			get
			{
				return this._smallIcon;
			}
			set
			{
				this._smallIcon = value;
			}
		}
		public ByteList AboutBoxImage
		{
			get
			{
				return this._aboutBoxImage;
			}
			set
			{
				this._aboutBoxImage = value;
			}
		}
		public string FormActionFields
		{
			get
			{
				return this._formActionFields;
			}
			set
			{
				this._formActionFields = value;
			}
		}
		public string FormActionPageProperty
		{
			get
			{
				return this._formActionPageProperty;
			}
			set
			{
				this._formActionPageProperty = value;
			}
		}
		public string PrimaryForm
		{
			get
			{
				return this._primaryForm;
			}
		}
		public string PrimaryView
		{
			get
			{
				return this._primaryView;
			}
		}
		public ArrayList Forms
		{
			get
			{
				return this._forms;
			}
			set
			{
				this._forms = value;
			}
		}
		public ArrayList PackingLists
		{
			get
			{
				return this._packingLists;
			}
			set
			{
				this._packingLists = value;
			}
		}
		public ArrayList SupportFiles
		{
			get
			{
				return this._supportFiles;
			}
			set
			{
				this._supportFiles = value;
			}
		}
		public ArrayList FormDataList
		{
			get
			{
				return this._formDataList;
			}
			set
			{
				this._formDataList = value;
			}
		}
		public ApplicationContainer()
		{
			this.Initialize();
		}
		internal ApplicationContainer(object[] rawData, Server server) : base(rawData, server)
		{
			this.Initialize();
			this.LoadRefs(server);
			try
			{
				if (server != null)
				{
					this._state = server.GetApplicationState(base.Name);
					IEnumerator enumerator = this.Forms.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							ApplicationForm applicationForm = (ApplicationForm)enumerator.get_Current();
							ARForm form = server.GetForm(applicationForm.Form);
							if (form.Properties.Contains(90011))
							{
								this._accessPoints.Add(applicationForm.Form);
							}
							if (!form.Properties.Contains(90007) || Convert.ToInt32(form.Properties.get_Item(90007)) == 0)
							{
								this._statisticForms.Add(applicationForm.Form);
							}
						}
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
			}
			catch (Exception var_2_E8)
			{
			}
		}
		private void Initialize()
		{
			this._version = 1;
			this._formsAsMaximized = false;
			this._autoLayoutStylesheet = "";
			this._addFormActionFields = false;
			this._resultListFixedHeader = false;
			this._disableBeginTask = false;
			this._defaultObjectPermissions = "";
			this._smallIcon = null;
			this._aboutBoxImage = null;
			this._formActionFields = "";
			this._formActionPageProperty = "";
			this._primaryForm = "";
			this._primaryView = "";
			this._forms = new ArrayList();
			this._packingLists = new ArrayList();
			this._supportFiles = new ArrayList();
			this._formDataList = new ArrayList();
			base.MembersModified = new BitVector32(base.MembersModified.get_Data() | 256);
			this._state = "";
			this._accessPoints = new ArrayList();
			this._statisticForms = new ArrayList();
		}
		internal void LoadRefs(Server server)
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			bool flag5 = false;
			bool flag6 = false;
			string text = "";
			string text2 = "";
			string str = "";
			int importOption = 0;
			int i = 0;
			int count = this._references.get_Count();
			while (i < count)
			{
				Reference reference = this._references.get_Item(i) as Reference;
				if (reference != null)
				{
					ExternalReference externalReference = reference as ExternalReference;
					int referenceType = reference.ReferenceType;
					if (referenceType <= 6)
					{
						if (referenceType != 2)
						{
							if (referenceType == 6)
							{
								if (flag5)
								{
									this._packingLists.Add(reference.Name);
									flag5 = false;
								}
							}
						}
						else
						{
							if (flag)
							{
								this._primaryForm = reference.Name;
								flag = false;
							}
							else
							{
								if (flag3)
								{
									text = reference.Name;
									flag3 = false;
								}
								else
								{
									if (flag6)
									{
										text = reference.Name;
										try
										{
											object qualification = server.DecodeQualifier(text2);
											text2 = server.FormatQualification(text, qualification);
										}
										catch (Exception var_16_2DA)
										{
											text2 = string.Format("encoded({0})", text2);
										}
										this._formDataList.Add(new ApplicationFormData(text, text2, Util.SplitIntoIntArray(str), importOption));
										flag6 = false;
									}
								}
							}
						}
					}
					else
					{
						switch (referenceType)
						{
						case 32769:
							this._smallIcon = ((externalReference != null) ? ((ByteList)externalReference.Value) : null);
							break;
						case 32770:
							this._formsAsMaximized = (externalReference != null && Convert.ToInt32(externalReference.Value) == 1);
							break;
						case 32771:
							flag3 = true;
							flag4 = true;
							break;
						case 32772:
							this._aboutBoxImage = ((externalReference != null) ? ((ByteList)externalReference.Value) : null);
							break;
						case 32773:
						case 32774:
						case 32775:
						case 32776:
							break;
						case 32777:
							flag = true;
							flag2 = true;
							break;
						case 32778:
							if (flag2)
							{
								this._primaryView = reference.Name;
								flag2 = false;
							}
							else
							{
								if (flag4)
								{
									string name = reference.Name;
									this._forms.Add(new ApplicationForm(text, name, this.PrimaryForm.CompareTo(text) == 0));
									flag4 = false;
								}
							}
							break;
						case 32779:
							this._disableBeginTask = (externalReference != null && Convert.ToInt32(externalReference.Value) == 1);
							break;
						default:
							if (referenceType != 32789)
							{
								switch (referenceType)
								{
								case 32831:
									this._autoLayoutStylesheet = ((externalReference != null) ? externalReference.Value.ToString() : "");
									break;
								case 32832:
									this._formActionFields = ((externalReference != null) ? externalReference.Value.ToString() : "");
									break;
								case 32833:
									flag6 = true;
									text2 = externalReference.Value.ToString();
									break;
								case 32835:
									this._defaultObjectPermissions = ((externalReference != null) ? externalReference.Value.ToString() : "");
									break;
								case 32836:
									this._addFormActionFields = (externalReference != null && Convert.ToInt32(externalReference.Value) == 1);
									break;
								case 32837:
									this._resultListFixedHeader = (externalReference != null && Convert.ToInt32(externalReference.Value) == 1);
									break;
								case 32838:
									this._formActionPageProperty = ((externalReference != null) ? externalReference.Value.ToString() : "");
									break;
								case 32839:
									this._version = ((externalReference != null) ? Convert.ToInt32(externalReference.Value) : 1);
									break;
								case 32840:
									flag5 = true;
									break;
								case 32841:
									if (flag6)
									{
										str = externalReference.Value.ToString();
									}
									break;
								case 32842:
									if (flag6)
									{
										importOption = Convert.ToInt32(externalReference.Value);
									}
									break;
								}
							}
							else
							{
								this._supportFiles.Add(new ApplicationSupportFile(externalReference.Description, (ByteList)externalReference.Value));
							}
							break;
						}
					}
				}
				i++;
			}
		}
		internal void SaveRefs(Server server)
		{
			base.MembersModified = new BitVector32(base.MembersModified.get_Data() | 256);
			if (this.Forms.get_Count() > 0)
			{
				base.AddItem(ApplicationContainer._formsIndicator);
			}
			if (this.PackingLists.get_Count() > 0)
			{
				base.AddItem(ApplicationContainer._packListIndicator);
			}
			if (this.SupportFiles.get_Count() > 0)
			{
				base.AddItem(ApplicationContainer._supportFileIndicator);
			}
			base.SetItemByRefType(new ExternalReference(32839)
			{
				Value = this.Version
			});
			base.SetItemByRefType(new ExternalReference(32770)
			{
				Value = Convert.ToInt32(this.FormsAsMaximized)
			});
			if (this.AutoLayoutStylesheet.get_Length() > 0)
			{
				base.SetItemByRefType(new ExternalReference(32831)
				{
					Value = this.AutoLayoutStylesheet
				});
			}
			base.SetItemByRefType(new ExternalReference(32836)
			{
				Value = Convert.ToInt32(this.AddFormActionFields)
			});
			base.SetItemByRefType(new ExternalReference(32837)
			{
				Value = Convert.ToInt32(this.ResultListFixedHeader)
			});
			base.SetItemByRefType(new ExternalReference(32779)
			{
				Value = Convert.ToInt32(this.DisableBeginTask)
			});
			if (this.DefaultObjectPermissions.get_Length() > 0)
			{
				base.SetItemByRefType(new ExternalReference(32835)
				{
					Value = this.DefaultObjectPermissions
				});
			}
			if (this.SmallIconImage != null)
			{
				base.SetItemByRefType(new ExternalReference(32769)
				{
					Value = this.SmallIconImage
				});
			}
			if (this.AboutBoxImage != null)
			{
				base.SetItemByRefType(new ExternalReference(32772)
				{
					Value = this.AboutBoxImage
				});
			}
			if (this.FormActionFields.get_Length() > 0)
			{
				base.SetItemByRefType(new ExternalReference(32832)
				{
					Value = this.FormActionFields
				});
			}
			if (this.FormActionPageProperty.get_Length() > 0)
			{
				base.SetItemByRefType(new ExternalReference(32838)
				{
					Value = this.FormActionPageProperty
				});
			}
			if (this.PrimaryForm.get_Length() > 0)
			{
				base.AddItem(ApplicationContainer._primaryFormIndicator);
				ExternalReference externalReference = new ExternalReference(32777);
				base.AddItem(externalReference);
				base.AddItem(new Reference(2, this.PrimaryForm));
			}
			if (this.PrimaryView.get_Length() > 0)
			{
				base.AddItem(new ExternalReference(32778)
				{
					Value = this.PrimaryView
				});
			}
			IEnumerator enumerator = this.Forms.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ApplicationForm applicationForm = (ApplicationForm)enumerator.get_Current();
					ExternalReference externalReference = new ExternalReference(32771);
					base.AddItem(externalReference);
					base.AddItem(new Reference(2, applicationForm.Form));
					base.AddItem(new ExternalReference(32778)
					{
						Value = applicationForm.Form
					});
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			enumerator = this.PackingLists.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					string name = (string)enumerator.get_Current();
					ExternalReference externalReference = new ExternalReference(32840);
					base.AddItem(externalReference);
					base.AddItem(new Reference(6, name));
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			enumerator = this.SupportFiles.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ApplicationSupportFile applicationSupportFile = (ApplicationSupportFile)enumerator.get_Current();
					base.AddItem(new ExternalReference(32789)
					{
						Description = applicationSupportFile.Name,
						Value = applicationSupportFile.Content
					});
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			enumerator = this.FormDataList.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ApplicationFormData applicationFormData = (ApplicationFormData)enumerator.get_Current();
					ExternalReference externalReference = new ExternalReference(32833);
					object qualifier = server.ParseQualification(applicationFormData.Form, null, applicationFormData.Qualification);
					externalReference.Value = server.EncodeQualifier(qualifier);
					base.AddItem(externalReference);
					base.AddItem(new ExternalReference(32841)
					{
						Value = Util.CollectionToString(applicationFormData.ImportMatchFields)
					});
					base.AddItem(new ExternalReference(32842)
					{
						Value = applicationFormData.ImportOption
					});
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
		}
		public void RemoveForm(string formName)
		{
			Reference reference = new Reference(2);
			reference.Name = formName;
			int num = base.References.IndexOf(reference);
			if (num >= 0 && num < base.References.get_Count())
			{
				this._references.RemoveRange(num - 1, 3);
			}
		}
		public void AddForm(ApplicationForm item)
		{
			base.MembersModified = new BitVector32(base.MembersModified.get_Data() | 256);
			this.RemoveForm(item.Form);
			int refType = item.IsPrimaryForm ? 32777 : 32771;
			ExternalReference item2 = new ExternalReference(refType);
			base.AddItem(item2);
			base.AddItem(new Reference(2)
			{
				Name = item.Form
			});
			Reference reference = new ExternalReference(32778);
			((ExternalReference)reference).Value = item.View;
			base.AddItem(reference);
		}
	}
}
